// <copyright file="DebuggerInstruction.cs" company="Codeplex project Eco.Contrib"> 
// The MIT License (MIT) 
// </copyright> 
// <author>Peter Buchmann</author> 

namespace Eco.Contrib
{
    using System;
    using System.Collections.Generic;
    using Eco.Handles;
    using Eco.ObjectRepresentation;
    using Eco.UmlCodeAttributes;
    using Eco.Windows.Forms;

    /// <summary>
    /// DebuggerInstruction: Starts a debugger instance
    /// </summary>
    public partial class DebuggerInstruction
    {
        /// <summary>
        /// Executes the function.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="variableList">The variable list.</param>
        /// <returns>Return value of executed function</returns>
        [UmlElement(Id = "ae2dfd34-4b19-47dd-9c11-5e7b277825e6")]
        protected internal override IElement ExecuteFunction(IEcoServiceProvider serviceProvider, IModifiableVariableList variableList)
        {
            using (EcoSpaceDebugger debugger = new EcoSpaceDebugger(serviceProvider as EcoSpace))
            {
                debugger.ShowDialog();
            }
            return null;
        }

        /// <summary>
        /// Inits the specified tokens.
        /// </summary>
        /// <param name="tokens">The tokens.</param>
        [UmlElement(Id = "f2d6ff9e-950b-4551-8b33-f6d35dca8f81")]
        protected internal override void Init(Dictionary<IList<EslToken>, Type> tokens)
        {
            if (tokens == null)
            {
                throw new EslException("Parameter is null");
            }

            List<EslToken> tokenList = new List<EslToken>();
            tokenList.Add(new EslToken(EslTokenType.Word, "Debugger"));
            tokens.Add(tokenList, this.GetType());
        }

        /// <summary>
        /// Parses the specified token list.
        /// </summary>
        /// <param name="tokenList">The token list.</param>
        /// <param name="ecoScript">The eco script.</param>
        /// <param name="fullExpression">if set to <c>true</c> [full expression].</param>
        [UmlElement(Id = "db575c6d-f77a-46d8-8147-195d480e1a94")]
        protected internal override void Parse(IList<EslToken> tokenList, EcoScript ecoScript, bool fullExpression)
        {
            EslToken token = GetNextToken(tokenList);
            RememberEcoScript(ecoScript, token);

            if (fullExpression)
            {
                EslToken tokenEnd = GetNextToken(tokenList);
                AssertInstructionEnd(tokenEnd);
            }
        }
    }
}